/**
 * 2012-2-17
 * @author 李亚松
 * @email  lysong01@gmail.com
 * Sequence.java	之所以不叫Genarator.java是因为并非使用了生成器设计模式，所以此类的扩展性不强
 */
package liyasong.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

public class Sequence {
	/*
	 * @param n为随机数范围最大值，m为随机数个数
	 */
	public static Collection<Integer> intRandSeq(int n, int m) {
		Random rand = new Random();
		Collection<Integer> seq = new ArrayList<Integer>();
		for (int i = 0; i < m; i++) {
			seq.add(rand.nextInt(n));
		}
		return seq;
	}
	
	public static Collection<Integer> intRandSeq() {
		return intRandSeq(100, 10);
	}
	
	/*
	 * @param start为起始自然数，step为相邻数之间的步长，m为自然数序列个数
	 */
	public static Collection<Integer> intSeq(int start, int step, int m) {
		Collection<Integer> seq = new ArrayList<Integer>();
		Integer[] array = new Integer[m];
		for (int i = 0; i < m; i++) {
			array[i] = start + step*i;
		}
		Collections.addAll(seq, array);		//这个方法不接受基础类型数组
		return seq;
	}
	
	public static Collection<Integer> intSeq() {
		return intSeq(0, 1, 10);
	}
	
	/*
	 * @param str为字符串，会被切割成不重复的单词
	 */
	public static Set<String> strSeq(String str) {
		Set<String> seq = new TreeSet<String>();
		Collections.addAll(seq, str.split(" "));
		return seq;
	}
	
	public static Set<String> strSeq() {
		String str = "I love you at the first eye of you";
		return strSeq(str);
	}
	
	/*
	 * @param 字符串s会被切割成不重复的字符集
	 */
	public static Set<Character> charSeq(String s) {
		Set<Character> ch = new TreeSet<Character>();
		for (Character c : s.toCharArray()) {
			ch.add(c);
		}
		return ch;
	}
	
	public static Set<Character> charSeq() {
		String s = "I love you at the first eye of you";
		return charSeq(s);
	}
}
